import React, { useImperativeHandle } from 'react';
import { Button, Modal, Space } from 'dw-mx';
import { ExclamationCircleOutlined } from 'dw-mx-icons';

export default React.forwardRef(function ConfirmBeforeCloseChild(props, ref) {
    useImperativeHandle(ref, () => ({
        beforeClose: async () => {
            return new Promise((resolve, reject) => {
                Modal.confirm({
                    icon: <ExclamationCircleOutlined />,
                    title: '提示',
                    content: '确认要关闭么?',
                    onOk() {
                        resolve();
                    },
                    onCancel() {
                        reject();
                    },
                });
            });
        },
    }));

    const handleClose = () => {
        props.closeDialog('HelloWorld!');
    };

    return (
        <>
            <h1>HelloWorld</h1>
            <Space>
                <Button onClick={handleClose}>close</Button>
            </Space>
        </>
    );
});
